package cn.ryh.designpatterndemo.prototypepattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName ShallowClonePrototype
 * @Description 浅拷贝
 * @Author RaoYH
 * @Date 2019/4/23
 */
public class ShallowClonePrototype implements Cloneable {

    private String name;

    private ArrayList<String> list = new ArrayList<>();

    @Override
    public ShallowClonePrototype clone() {
        ShallowClonePrototype shallowClonePrototype = null;
        try {
            shallowClonePrototype = (ShallowClonePrototype) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return shallowClonePrototype;
    }

    @Override
    public String toString() {
        return "ShallowClonePrototype{" +
                "name='" + name + '\'' +
                ", list=" + list +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getList() {
        return list;
    }

    public void setValue(String name) {
        this.list.add(name);
    }
}
